# -*- coding:utf-8 -*-
import time

import datetime

from Public_way.AutoTestLog import Logger
from selenium.webdriver.support.ui import WebDriverWait


class VideoCaseD:
    def __init__(self, driver):
        self.driver = driver

    Logger.initLogger('AutoTest' + '_Doctor_way_' + datetime.datetime.now().strftime('%Y%m%d%H%M%S'))

    # 专家拒诊
    def RefuceUser(self, message):
        name = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_patient_name'))
        dis = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_symptom'))
        print '患者的名字是 %s' % name.text.encode('utf-8')
        print '患者的病情描述 %s' % dis.text.encode('utf-8')
        time.sleep(2)
        # 点击下一步
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/ll_next_patient')).click()
        # 点击输入框
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/et_sendmessage')).send_keys(message)
        # 点击发送按钮
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/btn_send')).click()
        # 点击完成按钮
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_complete')).click()

    # 专家接诊
    def Start_D_Video(self, message):
        logger2 = Logger()
        logger2.log('进入患者病历界面了')
        name = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_patient_name'))
        dis = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_symptom'))
        logger2.log('医生端-查看患者的名字是 %s' % name.text.encode('utf-8'))
        logger2.log('医生端-查看患者的病情描述 %s' % dis.text.encode('utf-8'))
        # 点击接诊
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_name('接诊')).click()
        logger2.log('医生端-专家发起视频，等待患者接听')
        time.sleep(5)
        # 查看
        moneyD = WebDriverWait(self.driver, 180).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_total_money'))
        logger2.log('医生端-专家收入为：%s' % moneyD.text.encode('utf-8'))
        # 写诊断建议
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_name('去填写')).click()
        logger2.log('医生端-去填写诊断建议')
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/et_sendmessage')).send_keys(message)
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/btn_send')).click()
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_complete')).click()
        logger2.log('医生端-诊断建议填写完成')
        # 开始时间
        StartTime = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_start_time'))
        # 结束时间
        EndTime = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_end_time'))
        # 总时长
        AllTime = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_total_time'))
        logger2.log('医生端-开始时间 %s' % StartTime)
        logger2.log('医生端-结束时间 %s' % EndTime)
        logger2.log('医生端-总时长 %s' % AllTime)
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/rl_back')).click()
        time.sleep(2)
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/back_rl')).click()
        logger2.log('医生端-返回到首页了')
        # 点击首页查余额
        WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_name('首页')).click()
        Money = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/fragment_home_tv_money'))
        logger2.log('医生-视频结束后的余额 %s ' % Money.text.encode('utf-8'))
